new Vue({
    el:"#use",
    data:{
        placeuses:[],
        page:"",
        startusetime:"",
        hh:"",
        mf:"",
        ss:""
    },
    filters: {
        formatDate: function (value) {
            let date = new Date(value);
            let y = date.getFullYear();
            let MM = date.getMonth() + 1;
            MM = MM < 10 ? ('0' + MM) : MM;
            let d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            return y + '-' + MM + '-' + d ;
        }
    },
    methods:{
        getPlaceUses(pageNum){
            var placeuses;
            var pages;
            $.ajax({
                url: "/getPlaceUseInfo",
                contentType: "application/json;charset=UTF-8",
                data: {'pageNum':pageNum},
                async:false,
                type: "get",
                success: function (data) {
                    placeuses = data.placeApplies
                    pages = data.pages
                }
            })
            this.placeuses = placeuses
            this.page = pages
        },
        placeUse(index,applyid,time,apply_start){
            let timearry = []
            var object = this
            this.getNow()
            //获得切割后的时间段
            timearry = this.timeArray(time)
            var j = parseInt(timearry[0])
            var k = parseInt(timearry[1])
            var now = parseInt(this.hh)
            if(apply_start===null){
                if((now===j || now > j) && now < k){
                    this.getStartUseTime()
                    $.ajax({
                        // 设置json的属性和值
                        url: "/placeUser",
                        contentType: "application/json;charset=UTF-8",
                        data: {'applyid':applyid,'time':this.startusetime},
                        async:false,
                        type: "get",
                        success: function (data) {
                            alert("场地开始使用")
                            object.placeuses[index].apply_start = object.startusetime
                        }
                    })
                }
            }else {
                alert("正在使用中...")
            }
            if(now===k || now > k){
                alert("超出时间，不可使用")
            }
            if(now < j){
                alert("尚未到时间")
            }
        },
        timeArray:function(time){
            return time.split('-')
        },
        //获取使用开始使用时间
        getStartUseTime(){
            this.startusetime = this.hh+":"+this.mf+":"+this.ss
        },
        getNow(){
            let hh = new Date().getHours();
            let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
            let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
            this.hh = hh
            this.mf = mf
            this.ss = ss
        }
    },
    created(){
        this.getPlaceUses(1)
    }
})